using NUnit.Framework;

// ReSharper disable InconsistentNaming
namespace NFreeMarker.Tests.Template
{
    public class TemplateTests_ProcessSequenceOperations
    {
        [TestFixture]
        public class When_concatenating_two_empty_sequences : TemplateTestsBase
        {
            [Test]
            public void Assure_the_resulting_sequence_is_empty()
            {
                SetTemplateContent("${(lettersA + lettersB)?size}");
                AddTemplateVariable("lettersA", new string[0]);
                AddTemplateVariable("lettersB", new string[0]);

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("0"));
            }
        }

        [TestFixture]
        public class When_concatenating_one_empty_and_one_non_empty_sequence : TemplateTestsBase
        {
            [Test]
            public void Assure_the_resulting_sequence_contains_the_values_from_the_non_empty_sequence()
            {
                SetTemplateContent("<#list lettersA + lettersB as letter>${letter}</#list>");
                AddTemplateVariable("lettersA", new [] { "a", "b" });
                AddTemplateVariable("lettersB", new string[0]);

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("ab"));
            }
        }

        [TestFixture]
        public class When_concatenating_two_non_empty_sequences : TemplateTestsBase
        {
            [Test]
            public void Assure_the_resulting_sequence_contains_the_values_from_both_the_non_empty_sequences()
            {
                SetTemplateContent("<#list lettersA + lettersB as letter>${letter}</#list>");
                AddTemplateVariable("lettersA", new [] { "a", "b" });
                AddTemplateVariable("lettersB", new [] { "c", "d" });

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("abcd"));
            }
        }

        [TestFixture]
        public class When_slicing_a_sequence_with_first_and_last_index : TemplateTestsBase
        {
            [Test]
            public void Assure_the_values_from_the_first_to_the_last_index_is_returned()
            {
                SetTemplateContent("<#list letters[1..2] as letter>${letter}</#list>");
                AddTemplateVariable("letters", new [] { "a", "b", "c", "d" });

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("bc"));
            }
        }

        [TestFixture]
        public class When_slicing_a_sequence_with_first_index_only : TemplateTestsBase
        {
            [Test]
            public void Assure_the_values_from_the_first_index_is_returned()
            {
                SetTemplateContent("<#list letters[2..] as letter>${letter}</#list>");
                AddTemplateVariable("letters", new [] { "a", "b", "c", "d" });

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("cd"));
            }
        }

    }
}
// ReSharper enable InconsistentNaming
